from itemFactory import ItemFactory
#from random import Random

class ItemGun(ItemFactory):
    
    def __init__(self):
        ItemFactory.__init__(self)
        self.setVar("texture", "itemGun")
        self.setVar("spawnRate", 10)
        self.spawnCount = 10
        
        self.setVar("sides",['t','t','t','t'])
        self.setVar("base", "itemGun")
        
    def update(self, cmd, args):
        ItemFactory.update(self, cmd, args)
        
        dt = args["dtime"]
        
        self.spawnCount -= dt
        if(self.spawnCount < 0):
            self.spawnCount = self.getVar("spawnRate")
            
            item = self.spawnItem()
            
            pos = self.getVar("pos")
            p = item.getVar("pos")
            v = item.getVar("vel")
            
            p.x = pos.x
            p.y = pos.y + 1
            v.x = 5 + (5 * self.rand.random())
            if(self.rand.random() < 0.5):
                v.x = v.x * -1
            v.y = 5 + (5 * self.rand.random())